
             
/**
 * 
 *
 * @File name:  AddTSuppliersAction.java   添加【供应商信息:T_SUPPLIERS】
 * @Create on:  2011-10-31 23:59:900
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        
package com.boho.estates.suppliers.action;

            
import java.sql.Connection;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.MessageService;

import com.boho.common.SystemUtils;
import com.boho.estates.po.TSuppliersPO;
import com.boho.estates.suppliers.common.Constant;

public class AddTSuppliersAction extends ActionImp {
	
	private String exception = "";
	
	private String suppliersType = "";
	
	private TSuppliersPO tSuppliersPO = new TSuppliersPO();
	private Connection con=null;
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			if(Constant.SUPPLIERS_TYPE_X.equalsIgnoreCase(suppliersType)){
				exception = Constant.X_EXCEPTION;
			}
			else if(Constant.SUPPLIERS_TYPE_Z.equalsIgnoreCase(suppliersType)){
				exception = Constant.Z_EXCEPTION;
			}
			atx.setErrorContext("BOHO_COMMON_1001", MessageService.getMessage("BOHO_COMMON_1001"),exception, ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		POUtils.insert(con, tSuppliersPO,false);
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		con = atx.getConection();
		String createBy = SystemUtils.getSessionUser(atx);
		Integer departmentNo;
		DynaBeanMap dbm = (DynaBeanMap)atx.getSessionValue(com.boho.common.Constant.SESSION_PERSON_BEAN);
		if(dbm != null){
			departmentNo = (Integer)dbm.get("DEPARTMENT_NO");
		}
		else{
			departmentNo = 1001;
		}
		
		suppliersType = atx.getStringValue("SUPPLIERS_TYPE");
		tSuppliersPO.setSuppliersType(suppliersType);
		tSuppliersPO.setSuppliersName(atx.getStringValue("SUPPLIERS_NAME"));
		tSuppliersPO.setSuppliersNature(atx.getStringValue("SUPPLIERS_NATURE"));
		tSuppliersPO.setDepartmentNo(departmentNo);
		tSuppliersPO.setContact(atx.getStringValue("CONTACT"));
		tSuppliersPO.setTelephone(atx.getStringValue("TELEPHONE"));
		tSuppliersPO.setAddress(atx.getStringValue("ADDRESS"));
		tSuppliersPO.setAssPhone(atx.getStringValue("ASS_PHONE"));
		tSuppliersPO.setFax(atx.getStringValue("FAX"));
		tSuppliersPO.setRemark(atx.getStringValue("REMARK"));
		tSuppliersPO.setCreateDate(new java.util.Date());
		tSuppliersPO.setCreateBy(createBy);
		return 1;
	}
}
